package model

import (
	"Blog/database"
	"fmt"
)

type Config struct {
	Name, RootUrl string
}
type Menu struct {
	Id, Name, Icon string
}

var Configs = Config{}
var Menus []Menu

func GetConfig() {
	rows := database.Db.QueryRow("select `value` from amibk_config where `key` = ?", "site_name")
	err := rows.Scan(&Configs.Name)
	if err != nil {
		return
	}
	rows = database.Db.QueryRow("select `value` from amibk_config where `key` = ?", "root_url")
	err = rows.Scan(&Configs.RootUrl)
	if err != nil {
		return
	}

}

func GetMenu() {
	ManyRow, _ := database.Db.Query("SELECT `id`,`name`,`icon` FROM amibk_menu ORDER BY `index`")
	lines := Menu{}
	for ManyRow.Next() {
		err := ManyRow.Scan(&lines.Id, &lines.Name, &lines.Icon)
		if err != nil {
			fmt.Println(err)
			return
		}
		Menus = append(Menus, lines)
	}
}
